package com.banzhi.shop.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.entity.Management.Management_Data;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by HT on 2017/5/11.
 */

public class ManagementPingPaiadapter extends BaseAdapter<Management_Data> {

    public ManagementPingPaiadapter(Context context, List<Management_Data> data) {
        super(context, data);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final Management_Data data = getData().get(position);
        viewHolder holder = null;
        if (convertView == null) {
            holder = new viewHolder();
            convertView = getInflater().inflate(R.layout.items_management_paixu, null);
            holder.name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.imageView = (ImageView) convertView.findViewById(R.id.iv_image);
            holder.ivdelete = (ImageView) convertView.findViewById(R.id.iv_delete);
            convertView.setTag(holder);
        }
        holder = (viewHolder) convertView.getTag();
        if (data.getLogo() != null) {
            Picasso.with(getContext()).load(data.getLogo()) .placeholder( R.mipmap.zhanweitu2).into(holder.imageView);
        }
        holder.name.setText(data.getName());
        holder.ivdelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.deleteGoods(data.getId(), position);
            }
        });
        return convertView;
    }

    class viewHolder {
        ImageView imageView;
        ImageView ivdelete;
        TextView name;
    }

    public interface onclickToDosomethingCallBack {
        void deleteGoods(String id, int position);
    }

    public void setCallBack(onclickToDosomethingCallBack callBack) {
        this.callBack = callBack;
    }

    private onclickToDosomethingCallBack callBack;
}
